package cn.cvs.config;


import cn.cvs.dao.impl.UserInfoDaoImpl;
import cn.cvs.service.UserInfoService;
import cn.cvs.service.impl.UserInfoServiceImpl;
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration  //相当于 applicationContext.xml
@ComponentScan(value = {"cn.cvs.dao","cn.cvs.service"})
@PropertySource(value = "classpath:database.properties")
public class AppConfig {

    @Value("${jdbc.driver}")
    private String  driver;
    @Value("${jdbc.url}")
    private String  url;
    @Value("${jdbc.username}")
    private String  username;
    @Value("${jdbc.password}")
    private String  password;

    @Bean
    public BasicDataSource dataSource(){
        BasicDataSource basicDataSource=new BasicDataSource();
        basicDataSource.setDriverClassName(driver);
        basicDataSource.setUrl(url);
        basicDataSource.setUsername(username);
        basicDataSource.setPassword(password);
        return basicDataSource;
    }

//    @Bean //相当于 <bean> id
//    public UserInfoDaoImpl userInfoDao(){
//        return new UserInfoDaoImpl();
//    }
//
//
//    @Bean
//    public UserInfoServiceImpl userInfoService(){
//        UserInfoServiceImpl userInfoService=new UserInfoServiceImpl();
//        //userInfoService.setUserInfoDao(userInfoDao());
//        return userInfoService;
//    }
}
